import axios from 'axios'
import {getToken} from "./utill/Token";
import {Message} from "element-ui";

const service = axios.create({
    baseURL:'/api',
    timeout:3000
});
//添加请求拦截器
service.interceptors.request.use((config)=>{
    config.headers['admin_token'] = getToken('admin_token');
    config.headers['bussiness_token'] = getToken('bussiness_token');
    config.headers['user_token'] = getToken('user_token');
    config.headers['token_type'] = getToken('token_type');
    return config;
},(error )=>{
    return Promise.reject(error())
});
//添加响应拦截器
service.interceptors.response.use((response)=>{
    let {status,msg} = response.data;
    if (status !== 200){
        Message.error(msg)
    }

    return response
},(error) => {
    let res = error.response;
    console.log(res);

    // if (res.data.status===450){
    //     window.location.href="http://localhost"
    // }
    if (res.status == 500){
        Message.error("未找到服务器");
    }


    return Promise.reject(error())
});

export default service

